﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace SmartRoomFinder.Helpers
{
    public class TextToBooleanConverter:MarkupExtension,IValueConverter
    {
        #region Converter
        private TextToBooleanConverter converter;
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new TextToBooleanConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Binding.DoNothing;
            }
            int num;
            if (int.TryParse(value.ToString(), out num))
            {
                return num;
            }
            return Binding.DoNothing;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
        #endregion
    }


    public class IntergerToVisibilityConverter : MarkupExtension, IValueConverter
    {
        #region Converter
        private IntergerToVisibilityConverter converter;
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new IntergerToVisibilityConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Binding.DoNothing;
            }
            return int.Parse(value.ToString()) != 0 ? "0" : "0.55";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
        #endregion
    }

    public class ValueToMinConverter : MarkupExtension, IValueConverter
    {
        #region Converter
        private ValueToMinConverter converter;
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new ValueToMinConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Binding.DoNothing;
            }
            return int.Parse(value.ToString()) == 0 ? 15 : 0;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
        #endregion
    }

    public class TextToColorConverter : MarkupExtension, IValueConverter
    {
        #region Converter
        private TextToColorConverter converter;
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new TextToColorConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Binding.DoNothing;
            }
            return value.ToString() == "Please check your search criteria" ? "Red" : "Black";
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
        #endregion
    }
}
